package com.cg.service.impl;

import com.cg.dao.DmItemCommentMapper;
import com.cg.dao.DmItemMapper;
import com.cg.dao.DmItemTypeMapper;
import com.cg.dto.*;
import com.cg.entity.DmItemComment;
import com.cg.service.DmItemService;
import com.cg.utils.RedisUtil;
import com.cg.vo.*;
import com.cg.vo.floor.FloorItemsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 节目表(DmItem)表服务实现类
 *
 * @author makejava
 * @since 2023-11-08 13:00:50
 */
@Service("dmItemService")
@Slf4j
public class DmItemServiceImpl implements DmItemService {
    @Resource
    private DmItemMapper dmItemMapper;

    @Resource
    private DmItemCommentMapper dmItemCommentMapper;

    @Resource
    private DmItemTypeMapper dmItemTypeMapper;

    @Resource
    private RedisUtil redisUtil;
    //获取所有的商品分类
    @Override
    public Dto<List<ItemInfoVo>> findItemAll() {
        return DtoUtil.returnDataSuccess(dmItemMapper.findItemAll());
    }

    //首页轮播图接口
    @Override
    public Dto<List<HotItems>> queryBanner() {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryBanner());
    }

    //今日推荐列表
    @Override
    public Dto<List<BannerVo>> queryTodayRecommend() {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryTodayRecommend());
    }

    //即将开售列表
    @Override
    public Dto<List<BannerVo>> queryToSaleItem() {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryToSaleItem());
    }

    //首页返回不同楼层展示数据
    @Override
    public Dto<List<FloorItemsVo>> queryFloorItems() {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryFloorItems());
    }

    //不同分类排行
    @Override
    public Dto<List<HotsVo>> queryHotitems(HotDto hotDto) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryHotitems(hotDto.getItemTypeId()));
    }

    //1. 根据分类查询轮播图
    @Override
    public Dto<List<HotItems>> querySlideShowPic(HotDto hotDto){
        return DtoUtil.returnDataSuccess(dmItemMapper.querySlideShowPic(hotDto.getItemTypeId()));
    }


    //根据商品ID返回商品详情页
    @Override
    public Dto<ItemDetailVo> queryItemDetail(Long id) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemDetail(id));
    }

    //根据商品id查询商品排期
    @Override
    public Dto<List<ItemSchedulerVo>> queryItemScheduler(ItemSchedulerDto itemSchedulerDto) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemScheduler(itemSchedulerDto.getItemId()));
    }

    //根据商品排期查询商品价格
    @Override
    public Dto<List<ItemPriceVo>> queryItemPrice(ItemPriceDto itemPriceDto) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemPrice(itemPriceDto.getScheduleId()));
    }

    //根据商品id查询剧评
    @Override
    public Dto<List<ItemCommentVo>> queryItemComment(ItemCommentDto itemCommentDto) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemComment(itemCommentDto.getId()));
    }

    //添加评论
    @Override
    public Dto addItemComment(AddItemCommentDto addItemCommentDto) {
        log.info("token:{}"+addItemCommentDto.getToken());
        if(addItemCommentDto.getToken()==null || addItemCommentDto.getToken().equals("")){
            return DtoUtil.returnEnum(DtoEnum.COMMON_EXCEPTION);
        }
        //添加
        DmItemComment dmItemComment = new DmItemComment();
        dmItemComment.setItemId(addItemCommentDto.getItemId());
        dmItemComment.setUserId(addItemCommentDto.getUserId());
        dmItemComment.setScore(addItemCommentDto.getScore());
        dmItemComment.setContent(addItemCommentDto.getComment());
        addItemCommentDto.setCreatedTime(new Date());
        addItemCommentDto.setUpdatedTime(new Date());
        dmItemCommentMapper.addItemComment(dmItemComment);
        return DtoUtil.returnSuccess();
    }

    //推荐接口
    @Override
    public Dto<List<ItemRecommendVo>> queryItemRecommend(@RequestBody ItemRecommendDto itemRecommendDto) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemRecommend(itemRecommendDto));
    }


    //查询分类接口
    @Override
    public Dto<List<QueryItemTypeVo>> queryItemType(Long parent) {
        return DtoUtil.returnDataSuccess(dmItemTypeMapper.queryItemType(parent));
    }

    //猜你喜欢接口
    @Override
    public Dto<List<QueryItemLikeVo>> queryItemLike(Long itemTypeId) {
        return DtoUtil.returnDataSuccess(dmItemMapper.queryItemLike(itemTypeId));
    }

    @Override
    public List<DayItemVo> queryItemByMonth(DayItemDto dto) {
        return dmItemMapper.queryItemByMonth(dto);
    }


}
